package com.cykj.pos.controller.api;

import java.util.List;
import java.util.Arrays;

import com.alibaba.fastjson.JSONObject;
import com.cykj.pos.domain.*;
import com.cykj.pos.service.IBizMerchantService;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.cykj.common.annotation.Log;
import com.cykj.common.core.controller.BaseController;
import com.cykj.common.core.domain.AjaxResult;
import com.cykj.common.enums.BusinessType;
import com.cykj.pos.service.IBizWalletNewService;
import com.cykj.common.utils.poi.ExcelUtil;
import com.cykj.common.core.page.TableDataInfo;

import javax.annotation.Resource;

/**
 * bizWalletNewController
 *
 * @author weijianbo
 * @date 2025-01-20
 */
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/pos/new" )
public class BizWalletNewController extends BaseController {

    private final IBizWalletNewService iBizWalletNewService;

    @Autowired
    private IBizMerchantService iBizMerchantService;

    /**
     * 查询bizWalletNew列表
     */
    @PreAuthorize("@ss.hasPermi('pos:new:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizWalletNew bizWalletNew) {
        startPage();
        List<BizWalletNew> list = iBizWalletNewService.queryList(bizWalletNew);
        return getDataTable(list);
    }

    /**
     * 导出bizWalletNew列表
     */
    @PreAuthorize("@ss.hasPermi('pos:new:export')" )
    @Log(title = "bizWalletNew" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(BizWalletNew bizWalletNew) {
        List<BizWalletNew> list = iBizWalletNewService.queryList(bizWalletNew);
        ExcelUtil<BizWalletNew> util = new ExcelUtil<BizWalletNew>(BizWalletNew.class);
        return util.exportExcel(list, "new" );
    }

    /**
     * 获取bizWalletNew详细信息
     */
    @PreAuthorize("@ss.hasPermi('pos:new:query')" )
    @GetMapping(value = "/{walletId}" )
    public AjaxResult getInfo(@PathVariable("walletId" ) Long walletId) {
        return AjaxResult.success(iBizWalletNewService.getById(walletId));
    }

    /**
     * 新增bizWalletNew
     */
    @PreAuthorize("@ss.hasPermi('pos:new:add')" )
    @Log(title = "bizWalletNew" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizWalletNew bizWalletNew) {
        return toAjax(iBizWalletNewService.save(bizWalletNew) ? 1 : 0);
    }

    /**
     * 修改bizWalletNew
     */
    @PreAuthorize("@ss.hasPermi('pos:new:edit')" )
    @Log(title = "bizWalletNew" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizWalletNew bizWalletNew) {
        return toAjax(iBizWalletNewService.updateById(bizWalletNew) ? 1 : 0);
    }

    /**
     * 删除bizWalletNew
     */
    @PreAuthorize("@ss.hasPermi('pos:new:remove')" )
    @Log(title = "bizWalletNew" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{walletIds}" )
    public AjaxResult remove(@PathVariable Long[] walletIds) {
        return toAjax(iBizWalletNewService.removeByIds(Arrays.asList(walletIds)) ? 1 : 0);
    }



    // app 点击钱包
    @PostMapping("/wallet/balance")
    public JSONObject walletBalance(@RequestBody BizWalletNew bizWalletNew){
        return iBizWalletNewService.walletBalance(bizWalletNew);
    }

    // 分润与机具返现 提现
    @PostMapping("/withdrawal/money")
    public AjaxResult withdrawalMoney(@RequestBody BizWalletNew bizWalletNew) {
        return iBizWalletNewService.withdrawalMoney(bizWalletNew);
    }

    // 奖励账户提现
    @PostMapping("/withdrawal/aizWithdrawal/money")
    public AjaxResult withdrawalAizWithdrawalMoney(@RequestBody AizWithdrawalWallet aizWithdrawalMoney) {
        return iBizWalletNewService.withdrawalAizWithdrawalMoney(aizWithdrawalMoney);
    }

    // app 返回提现政策区间
    @PostMapping("/withdrawal/interval")
    public AjaxResult withdrawalInterval(@RequestBody BizMerchant bizMerchant){
        return iBizMerchantService.withdrawalInterval(bizMerchant);
    }

    //app 提现模板提交
    @PostMapping("/withdrawal/template/saveOrUpdate")
    public AjaxResult withdrawalTemplateSaveOrUpdate(@RequestBody WithdrawalRateTemplate withdrawalRateTemplate){
        return iBizWalletNewService.withdrawalTemplateSaveOrUpdate(withdrawalRateTemplate);
    }

    //app 提现模板回显
    @PostMapping("/withdrawal/template/showBack")
    public AjaxResult withdrawalTemplateShowBack(@RequestBody WithdrawalRateTemplate withdrawalRateTemplate){
        return iBizWalletNewService.withdrawalTemplateShowBack(withdrawalRateTemplate);
    }

     // app 显示钱包总余额
    @PostMapping("/total/wallet/balance")
    public AjaxResult totalWalletBalance(@RequestBody BizWalletNew bizWalletNew){
        return iBizWalletNewService.totalWalletBalance(bizWalletNew);
    }


    // 测试 提现分润
    @PostMapping("/test/share/withdrawal")
    public void testShareWithdrawal(@RequestBody BizWithdrawalRecords bizWithdrawalRecords){
        iBizWalletNewService.testShareWithdrawal(bizWithdrawalRecords);
    }



}
